package com.zh.note.huawei.twohundred.优雅数组;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @Author: zhanghuan
 * @date: 2023/8/10 20:43
 * @description: create it
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // int n = sc.nextInt();
        // int k = sc.nextInt();
        // int[] arr = new int[n];
        //
        // for (int i = 0; i < n; i++) {
        //     arr[i] = sc.nextInt();
        // }
        int n = 7;
        int k = 2;
        int[] arr = {1, 2, 3, 1, 2, 3, 1};
        System.out.println(solution(arr, n, k));
    }

    private static int solution(int[] arr, int n, int k) {

        int res = 0;
        for (int i = 0; i < n; i++) {
            Map<Integer, Integer> map = new HashMap<>();
            for (int j = i; j < n; j++) {
                int key = arr[j];
                map.put(key, map.getOrDefault(key, 0) + 1);
                if (map.get(key) >= k) {
                    res += n - j;
                    break;
                }
            }
        }
        return res;
    }
}
